Page({
    data: {
        username: '',
        usernameErr: false,
        password: '',
        passwordErr: false,
        buttonLoading: false,
        // customerInfo: null,
    },
    onLoad() {
        // this.getServer()
    },
    inputFocus() {
        this.setData({ usernameErr: false, passwordErr: false })
    },
    login() {
        if (this.data.username === '') return this.setData({ usernameErr: true })
        if (this.data.username.length !== 11) {
            this.setData({ usernameErr: true })
            return wx.showToast({
                title: '账号必须是11位手机号码',
                icon: 'none'
            })
        }


        if (this.data.password === '') return this.setData({ passwordErr: true })
        this.setData({ buttonLoading: true })
        this.request({
            url: '/supplier/login',
            method: 'POST',
            login: false,
            data: {
                mobile: this.data.username,
                password: this.data.password
            }
        }, res => {
            wx.setStorageSync('Authorization', res.data.access_token)
            getApp().globalData.userInfo = {
                city: res.data.city,
                title: res.data.title,
                mobile: res.data.mobile,
                phone: res.data.phone
            }
            const eventChannel = this.getOpenerEventChannel()
            eventChannel.emit('login');
            wx.navigateBack()
        }, null, () => { this.setData({ buttonLoading: false }) })
    },
    /**获取客服信息 */
    // getServer() {
    //     this.request({
    //         url: '/supplier/index/config?type=1',
    //         login: false
    //     }, res => {
    //         this.setData({ customerInfo: res.data })
    //     })
    // },
    // /**拨打电话 */
    // tel() {
    //     wx.makePhoneCall({
    //         phoneNumber: this.data.customerInfo.mobile
    //     })
    // },
    onUnload() {
        const eventChannel = this.getOpenerEventChannel()
        eventChannel.emit('setAllow_jump');
    }
})